import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter_jd/pages/tabbar/cart/controller.dart';
import 'package:flutter_jd/ui/pages/cart/goods_item.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:get/get_state_manager/get_state_manager.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class CartGoodsList extends GetWidget<CartController> {
  final int index;
  CartGoodsList(this.index);

  @override
  Widget build(BuildContext context) {
    return Column(
      children: List.generate(
        controller.productList[index]['children'].length,
        (cIndex) => Container(
          height: 130.h,
          color: Colors.white,
          child: Slidable(
            key: Key(cIndex.toString()),
            controller: controller.slidableController,
            actionPane: SlidableDrawerActionPane(),
            showAllActionsThreshold: 1,
            actionExtentRatio: 0.17,
            fastThreshold: 1,
            child: Container(
              padding: EdgeInsets.symmetric(
                horizontal: 10.r,
                vertical: 10.r,
              ),
              child: CartGoodsItem(index, cIndex),
            ),
            secondaryActions: List.generate(
              controller.slideButtonList.length,
              (index) => SlideAction(
                child: Container(
                  alignment: Alignment.center,
                  decoration: BoxDecoration(
                    gradient: LinearGradient(
                      begin: Alignment.topLeft,
                      end: Alignment.bottomRight,
                      colors: controller.slideButtonList[index]['color'],
                    ),
                  ),
                  child: Text(
                    controller.slideButtonList[index]['name'],
                    style: TextStyle(
                      color: controller.slideButtonList[index]['textColor'],
                      fontSize: 14,
                      fontWeight: FontWeight.w500,
                    ),
                  ),
                ),
              ),
            ),
          ),
        ),
      ),
    );
  }
}
